import os, sys
import shutil
# 源文件夹
path_input = r'\\172.18.5.225\data2\wangshuan\TAI40-II\测试'
# 列表中填写文件名或文件夹名
list_move = ['label_dhq_ok.txt', '删除文件夹','删除文件.txt']

for root_dirs, sub_dirs, files in os.walk(path_input):
    for sub_dir in sub_dirs:  # 删除文件夹
        if sub_dir in list_move:
            path_move = os.path.join(root_dirs, sub_dir)
            try:
                print(path_move)
                shutil.rmtree(path_move)
            except:
                pass
    for file in files:  # 删除文件
        if (file in list_move) or (file.endswith('.dat')):
            path_move = os.path.join(root_dirs, file)
            try:
                print(path_move)
                os.unlink(path_move)
            except:
                pass
